package cn.zhenxin.autocode.annotation.data;

import java.lang.reflect.Method;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.ReflectionUtils;


/**
 * 监听ContextRefresedEvent 事件
 * @author jksk8
 * 
 * SmartInitializingSingleton 
 * 
 */
@Service
public class FillDataLoadListener implements BeanPostProcessor  {
	    @Override
	    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
	    	System.out.println(beanName);
	    	return bean;
	    }

	    @Override
	    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
	        Method[] methods = ReflectionUtils.getAllDeclaredMethods(bean.getClass());
	        if (methods != null) {
	            for (Method method : methods) {
	            	Service myListener =  AnnotationUtils.findAnnotation(method, Service.class);
	            	if(myListener != null){
	            		System.out.println(myListener);
	            	}
	            }
	        }
	        return bean;
	    }

}
